package com.example.himalayaproject.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import com.example.himalayaproject.R;
import com.example.himalayaproject.activity.OwnerLoginActivity;
import com.example.himalayaproject.activity.SettingActivity;
import com.example.himalayaproject.adapter.OwnerRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class OwnerFragment extends Fragment implements OwnerRecyclerAdapter.OnChildClickListener, View.OnClickListener {
    private RecyclerView recycler;
    private int imageIds[] = new int[]{R.mipmap.me_order, R.mipmap.msg_center_img, R.mipmap.shoppingcart, R.mipmap.xibi, R.mipmap.my_collect_img, R.mipmap.play_record_img, R.mipmap.praised_img, R.mipmap.my_points_img, R.mipmap.me_mall, R.mipmap.me_order, R.mipmap.me_setting_coupon, R.mipmap.me_game, R.mipmap.me_setting_carmode, R.mipmap.myspace_my_device, R.mipmap.setting_findfriend, R.mipmap.bind_img, R.mipmap.setting_tallour, R.mipmap.setting_entry};
    private String titles[] = new String[]{"主播管理中心", "消息中心", "已购声音", "喜币余额", "我的订阅", "播放历史", "赞过的", "我的积分", "喜马拉雅商城", "我的商城订单", "我的优惠券", "游戏中心", "车载模式", "智能硬件设备", "找听友", "账号绑定", "意见反馈", "设置"};
    private ImageView setting_iv;
    private ImageView setting2_iv;
    private TextView setting_tv;


    public OwnerFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_owner, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recycler = (RecyclerView) view.findViewById(R.id.owner_fragment_recyclerview);
        setting_iv = ((ImageView) view.findViewById(R.id.owner_fragment_setting_iv));
        setting2_iv = (ImageView) view.findViewById(R.id.owner_fragment_logon_iv);
        setting_tv = (TextView) view.findViewById(R.id.owner_fragment_logon_tv);
        List<Integer> imageList = new ArrayList<>();
        for (int i = 0; i < imageIds.length; i++) {
            imageList.add(imageIds[i]);
        }
        List<String> titleList = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            titleList.add(titles[i]);
        }
        OwnerRecyclerAdapter adapter = new OwnerRecyclerAdapter(getContext(), imageList, titleList);
        adapter.setListener(this);
        recycler.setAdapter(adapter);
        setting_iv.setOnClickListener(this);
        setting2_iv.setOnClickListener(this);
        setting_tv.setOnClickListener(this);
    }

    @Override
    public void onChildClick(int position) {
        Intent intent = new Intent();
        switch (position) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 6:
            case 10:
            case 14:
            case 15:
                intent.setClass(getContext(), OwnerLoginActivity.class);
                break;
            case 17:
                intent.setClass(getContext(), SettingActivity.class);
                break;
            default:
                intent.setClass(getContext(), OwnerLoginActivity.class);
                break;
        }
        startActivity(intent);
        getActivity().overridePendingTransition(R.anim.anim_exit, R.anim.back_exit);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.owner_fragment_setting_iv:
                intent.setClass(getContext(), SettingActivity.class);
                break;
            case R.id.owner_fragment_logon_iv:
                intent.setClass(getContext(),OwnerLoginActivity.class);
                break;
            case R.id.owner_fragment_logon_tv:
                intent.setClass(getContext(),OwnerLoginActivity.class);
                break;
        }
        startActivity(intent);
        getActivity().overridePendingTransition(R.anim.anim_exit, R.anim.back_exit);
    }
}
